package com.yonyou.ucf.mdf.app.isvdxq.common;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class JobScheduler {
    private static String JOB_GROUP_NAME = "DxqJob01";
    private static String TRIGGER_GROUP_NAME = "trigger1";
    //创建调度器
    public static Scheduler getScheduler() throws SchedulerException {
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        return schedulerFactory.getScheduler();
    }

    // 执行任务
    public static void run() throws SchedulerException{
        //创建任务
        JobDetail jobDetail = JobBuilder.newJob(DxqJob01.class).withIdentity(JOB_GROUP_NAME, "group11").build();
        //创建触发器 每3秒钟执行一次
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity(TRIGGER_GROUP_NAME, "group21")
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(3).repeatForever())
                .build();
        Scheduler scheduler = getScheduler();
        //将任务及其触发器放入调度器
        scheduler.scheduleJob(jobDetail, trigger);
        //调度器开始调度任务
        // 启动
        if (!scheduler.isShutdown()) {
            scheduler.start();
        }
    }
    //定时任务启动
//    public static void main(String[] args) throws SchedulerException {
//        JobScheduler jobScheduler = new JobScheduler();
//        jobScheduler.run();
//    }
}
